package com.example.springboot.controller;

import com.example.springboot.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
import com.example.springboot.service.CommentService;
import com.example.springboot.pojo.Comment;
import com.example.springboot.pojo.Result;
@RestController
@CrossOrigin
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    private CommentService commentService;
    @PostMapping("/create")
    public Result create(@RequestBody Comment comment)
    {
        commentService.create(comment);
        return Result.success();
    }
    @DeleteMapping("/delete")
    public Result delete(Integer id)
    {
        commentService.delete(id);
        return Result.success();
    }
    @GetMapping("/findAll")
    public Result findAll()
    {
        List<Comment> comments = commentService.findAll();
        return Result.success(comments);
    }
    @GetMapping("/findByUserName")
    public Result findByUserName(@RequestParam String username)
    {
        List<Comment> comment=commentService.findByUserName(username);
        return Result.success(comment);
    }
    @GetMapping("/selectPage")
    public Result selectPage(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        return Result.success(commentService.selectPage(pageNum, pageSize));
    }
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        commentService.deleteBatch(ids);
        return Result.success();
    }

    // 根据用户名查询
    @GetMapping("/findByUserId")
    public Result findByUserId() {
        List<Comment> comments = commentService.findByUserId();
        return Result.success(comments);
    }
}
